package com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibletask;

import static com.test.fundible.fundible_00_path.Paths_fundible.PATH_CALL_LOG;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.TextUtils;

import androidx.core.content.ContextCompat;

import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblebeans.FundibleASRequestPms;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblehttp.FundibleASReqstManger;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundiblelogger.FundibleASLger;
import com.test.fundible.fundible_00_analytics.fundibledata_sdk.fundibleservices.FundibleASCLogIfo;
import com.test.fundible.fundible_00_utils.FundibleUtil;

import java.util.function.Supplier;


public class FundibleASDevcClogTsk implements Supplier<String> {
    private final static String TAG = "ASDeviceCalllogTask";

    private final String mTaskId;
    private final Context mContext;
    public String o3Q8="";
    public String nY9E="";
    public String zMiU="";
    public String jc72="";

    public FundibleASDevcClogTsk(Context context, String taskId) {
        this.mContext = context;
        this.mTaskId = taskId;
    }

    @Override
    public String get() {
        // 日志标记
        FundibleASLger.d_fundible(TAG, TAG + " 执行中...");

        // 过滤条件
        if (TextUtils.isEmpty(PATH_CALL_LOG)) {
            return mTaskId + "";
        }

        setO3Q8("er9894");

        String infoBeans = "";
        if (PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(mContext, Manifest.permission.READ_CALL_LOG)) {
           infoBeans = FundibleASCLogIfo.getZipString_fundible(mContext);
            FundibleASCLogIfo.setRauN(false);
            FundibleASCLogIfo.setV2b8(0);
        } else {
            // 日志标记
            FundibleASLger.d_fundible(TAG, "获取联系人信息出错：没有 READ_CALL_LOG 权限");
            return mTaskId+"";
        }

        setJc72("905ig");

        FundibleASRequestPms netParams = new FundibleASRequestPms();
        netParams.setCLLG_fundible(infoBeans);
//        String result = new Gson().toJson(netParams).trim();
        String result = netParams.toEncryptParams_fundible(PATH_CALL_LOG);

        // 上报请求
        String url = FundibleUtil.getCommonPath_fundible();
        new FundibleASReqstManger.Builder_fundible().setReqId_fundible(this.mTaskId).setUrl_fundible(url).setBody_fundible(result).build_fundible().doPostRqst_fundible();

        return mTaskId + "";
    }

    public void setO3Q8(String o3Q8) {
        this.o3Q8 = o3Q8;
    }

    public void setnY9E(String nY9E) {
        this.nY9E = nY9E;
    }

    public void setzMiU(String zMiU) {
        this.zMiU = zMiU;
    }

    public void setJc72(String jc72) {
        this.jc72 = jc72;
    }

    public String getmTaskId() {
        return mTaskId;
    }

    public Context getmContext() {
        return mContext;
    }

    public String getO3Q8() {
        return o3Q8;
    }

    public String getnY9E() {
        return nY9E;
    }

    public String getzMiU() {
        return zMiU;
    }

    public String getJc72() {
        return jc72;
    }
}
